package cn.hls.web.tag;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import cn.hls.constant.security.Permission;
import cn.hls.service.ACLService;

 
/**  
* @fileName: SecurityFunctions.java 
* @Description: JSTL函数,主要功能是可以完成权限的即时认证
* @author: yinghui.zhang
* @email:  uuhui@163.com  
* @date 2015年7月22日 
* @version V1.0  
*/ 
public class SecurityFunctions {

	private static Log logger = LogFactory.getLog(SecurityFunctions.class);
	private  static ACLService aclService;
	
	public static boolean hasPermission(long userId,String code,String permission){
		try {
			return aclService.hasPermissionByResourceCode(userId, code, Permission.PERMISSIONMAP.get(permission.toUpperCase()));
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("系统权限按钮查询出错！");
		}
		return false;
	}
	
	public  boolean hasExtPermission(long userId,String code,String permission){
		try {
			return aclService.hasPermissionByResourceCode(userId, code, Permission.PERMISSIONMAP.get(permission.toUpperCase()),false);
		} catch (Exception e) {
			logger.error("扩展权限按钮查询出错！");
		}
		return false;
	}

	public ACLService getAclService() {
		return aclService;
	}

	public void setAclService(ACLService aclService) {
		SecurityFunctions.aclService = aclService;
	}
 
	
}
